from enum import Enum, auto


class JavaNodeType(str, Enum):
    """Java AST节点类型枚举"""

    # 顶层声明
    PROGRAM = "program"                                     # 整个Java程序的根节点
    PACKAGE_DECLARATION = "package_declaration"             # 包声明，如：package com.example
    IMPORT_DECLARATION = "import_declaration"               # 导入声明，如：import java.util.List
    CLASS_DECLARATION = "class_declaration"                 # 类声明，如：public class MyClass
    INTERFACE_DECLARATION = "interface_declaration"         # 接口声明，如：public interface MyInterface
    ENUM_DECLARATION = "enum_declaration"                   # 枚举声明，如：public enum Status
    ANNOTATION_DECLARATION = "annotation_type_declaration"  # 注解类型声明，如：@interface MyAnnotation
    CLASS_BODY = "class_body"                               # 类主体
    INTERFACE_BODY = "interface_body"                       # 接口主体

    # 修饰符和类型
    MODIFIERS = "modifiers"                             # 修饰符集合，包含public、private、protected、static等
    TYPE_IDENTIFIER = "type_identifier"                 # 类型标识符
    ARRAY_TYPE = "array_type"                           # 数组类型，如：int[]、String[]
    VOID_TYPE = "void_type"                             # void返回类型
    SCOPED_TYPE_IDENTIFIER = "scoped_type_identifier"   # 限定作用域的类型标识符，如：java.util.List
    SCOPED_IDENTIFIER = "scoped_identifier"             # 带作用域的普通标识符， 如：System.out、OuterClass.InnerClass.value

    # java基本类型
    INTEGRAL_TYPE = "integral_type"                 # 整数类型，包括byte、short、int、long、char
    FLOATING_POINT_TYPE = "floating_point_type"     # 浮点数类型，包括float、double
    BOOLEAN_TYPE = "boolean_type"                   # 布尔类型

    # 方法相关
    METHOD_DECLARATION = "method_declaration"               # 方法声明，包含方法名、参数、返回类型等
    CONSTRUCTOR_DECLARATION = "constructor_declaration"     # 构造方法声明
    FORMAL_PARAMETERS = "formal_parameters"                 # 形式参数列表，即方法参数列表的容器
    FORMAL_PARAMETER = "formal_parameter"                   # 单个形式参数声明
    THROWS = "throws"                                       # 异常抛出声明，如：throws Exception

    # 字段相关
    FIELD_DECLARATION = "field_declaration"                 # 字段声明，如：private int count;
    VARIABLE_DECLARATOR = "variable_declarator"             # 变量声明器，包含变量名和可选的初始化表达式
    FIELD_ACCESS = "field_access"                           # 访问对象的字段或静态字段的表达式

    # 语句
    BLOCK = "block"                                         # 代码块，由花括号{}包围的代码段
    IF_STATEMENT = "if_statement"                           # if条件语句
    FOR_STATEMENT = "for_statement"                         # for循环语句
    WHILE_STATEMENT = "while_statement"                     # while循环语句
    DO_STATEMENT = "do_statement"                           # do-while循环语句
    TRY_STATEMENT = "try_statement"                         # try语句块
    CATCH_CLAUSE = "catch_clause"                           # catch异常捕获子句
    FINALLY_CLAUSE = "finally_clause"                       # finally子句
    RETURN_STATEMENT = "return_statement"                   # return返回语句

    # 表达式
    ASSIGNMENT_EXPRESSION = "assignment_expression"         # 赋值表达式，如：x = 42
    BINARY_EXPRESSION = "binary_expression"                 # 二元表达式，如：a + b
    UNARY_EXPRESSION = "unary_expression"                   # 一元表达式，如：!flag、++count
    METHOD_INVOCATION = "method_invocation"                 # 方法调用表达式，如：object.method()
    OBJECT_CREATION = "object_creation_expression"          # 对象创建表达式，如：new MyClass()

    # 注释
    LINE_COMMENT = "line_comment"                           # 单行注释，以//开头
    BLOCK_COMMENT = "block_comment"                         # 块注释，包括/* */和/** */（JavaDoc）

    # 标识符和字面量
    IDENTIFIER = "identifier"                               # 标识符，如变量名、方法名等
    STRING_LITERAL = "string_literal"                       # 字符串字面量，如："Hello World"
    TYPE_LIST = "type_list"                                 # 类型列表

    # 注解相关
    ANNOTATION_TYPE_BODY = "annotation_type_body"                                   # 注解类型的主体部分
    ANNOTATION_TYPE_ELEMENT_DECLARATION = "annotation_type_element_declaration"     # 注解元素声明
    ANNOTATION_ARGUMENT_LIST = "annotation_argument_list"                           # 注解参数列表
    DEFAULT = "default"                                                             # 注解元素或方法参数的默认值
    ANNOTATION = "annotation"                                                       # 使用注解
    MARKER_ANNOTATION = "marker_annotation"                                         # 使用标识注解，如@Controller

    # 实现与继承
    SUPERCLASS = "superclass"               # 继承的父类
    SUPER_INTERFACES = "super_interfaces"   # 实现的接口


    @classmethod
    def is_class_declaration(cls, node_type: str) -> bool:
        """判断是否是类声明节点"""
        return node_type in {
            cls.CLASS_DECLARATION.value,
            cls.INTERFACE_DECLARATION.value,
            cls.ENUM_DECLARATION.value,
            cls.ANNOTATION_DECLARATION.value
        }

    @classmethod
    def is_comment(cls, node_type: str) -> bool:
        """判断是否是注释节点"""
        return node_type in {
            cls.LINE_COMMENT.value,
            cls.BLOCK_COMMENT.value
        }

    @classmethod
    def is_return_type(cls, node_type: str) -> bool:
        """判断是否是返回类型节点"""
        return node_type in {
            cls.TYPE_IDENTIFIER.value,
            cls.VOID_TYPE.value,
            cls.SCOPED_TYPE_IDENTIFIER.value
        } or cls.is_base_parameter_type(node_type)

    @classmethod
    def is_parameter_type(cls, node_type: str) -> bool:
        """判断是否是参数类型节点"""
        return node_type in {
            cls.TYPE_IDENTIFIER.value,
            cls.SCOPED_TYPE_IDENTIFIER.value
        } or cls.is_base_parameter_type(node_type)

    @classmethod
    def is_base_parameter_type(cls, node_type: str) -> bool:
        """判断是否是Java基本类型节点"""
        return node_type in {
            cls.INTEGRAL_TYPE.value,
            cls.FLOATING_POINT_TYPE.value,
            cls.BOOLEAN_TYPE.value
        }
